<?php
/********************************************************/
/* Module Name:  new_natureofcase.php						    */
/* Description: this will add new case to nature of case*/
/*    table												*/
/* Written by: Maria Cielo Carreno							*/
/********************************************************/
 

 function successwindow()
 {
 ?>
	<html>
	<head>
	<link href="default.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
	<div id="fulladmin">
	<div id="simple">
	<center><h1>Mediatrix Database</h1><br>
	<form  action="dashboard.php" method="get">
	<div style="padding:4px; border:0px solid red; color:red;" align="center">Saved! Please click the button to continue..</div>
	<center> <input type="submit" value="Continue" /> <center>
	</form>
	</div>
	</div>
	</body>
	</html>
<?php
 }
 
 function renderForm($Ndescription, $error)
 {
 ?>
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <html>
 <head>
 <link href="default.css" rel="stylesheet" type="text/css" />
 <title>New Nature of Case</title>
 </head>
 <body>
 <div id="fulladmin">
  <div style ='width: 550px; margin: 180px auto 0;'> 
 <center><h1>New Nature of Case Record</h1><br>
 <table border='0' cellpadding='10'>
   <tr><th>
 <?php
session_start();
//If your session isn't valid, it returns you to the login screen for protection
if(empty($_SESSION['myusername'])){
 header("location:main_login.php");
}
//echo $_SESSION['myusername'];
?>
 <?php 
 // if there are any errors, display them
 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 
 
 <form action="" method="post">
 <div>
 <strong>Description: *</strong> <input type="text" name="Ndescription" size="50" value="<?php echo $Ndescription; ?>" /><br/>
  <input type="submit" name="submit" value="Submit">
 <input type="submit" name="back" value="Back">
 </th></tr></table>
 </div>
 </form> 
 </div><div>
 <div id="footer"><center>Return to main <a href="dashboard.php"><font color="red">Control Panel</font></a>, or you can <a href="log_out.php?id=<?php echo $_SESSION['userid']; ?>"><font color="red">Log Out</font></a></center></div>

 </body>
 </html>
 <?php 
 }
 
 
 

 // connect to the database
 include('connect-db.php');
 
 // check if the form has been submitted. If it has, start to process the form and save it to the database
 if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
	$Ndescription = mysql_real_escape_string(htmlspecialchars($_POST['Ndescription']));

	// check to make sure both fields are entered
	if ($Ndescription == '')
	{
	// generate error message
		$error = 'ERROR: Please fill in all required fields!';
 
	// if either field is blank, display the form again
		renderForm($Ndescription, $error);
	}
	else
	{
	// save the data to the database
		mysql_query("INSERT natureofcase(Ndescription) VALUES('$Ndescription')")
		or die(mysql_error()); 
 
		successwindow();
	// once saved, redirect back to the view page
	//	header("Location: toolbox.php?page=1"); 
	}
 }
 else
 // if the form hasn't been submitted, display the form
 {
    if(isset($_POST['back']))
	   header("Location: toolbox.php?page=1");
	else
	   renderForm('','');
 }
?> 